import { Logger } from "../../../../../Core/Module/Log/Logger";
import { NetServices } from "../../../../../Core/Module/Network/NetServices";
import { HashSet } from "../../../../../Support/Share/Lib/Collections/HashSet";
import { GetTypeOf } from "../../../../../Decorator/Decorator";
import { OpcodeRangeDefine } from "../../../../../Core/Module/Network/OpcodeRangeDefine";
import { OuterMessage } from "../../../Generate/Share/Message/OuterMessage_C_10001";

export class OpcodeHelper {

    private static readonly ignoreDebugLogMessageSet = new HashSet<number>();

    private static IsNeedLogMessage(opcode: number): boolean {
        if (this.ignoreDebugLogMessageSet.Size() == 0) {
            this.ignoreDebugLogMessageSet.Add(OuterMessage.C2G_Ping);
            this.ignoreDebugLogMessageSet.Add(OuterMessage.G2C_Ping);
            this.ignoreDebugLogMessageSet.Add(Number.MAX_SAFE_INTEGER);
        }
        if (this.ignoreDebugLogMessageSet.Contains(opcode)) {
            return false;
        }
        return true;
    }

    public static IsOuterMessage(opcode: number): boolean {
        return opcode < OpcodeRangeDefine.OuterMaxOpcode;
    }

    public static IsInnerMessage(opcode: number): boolean {
        return opcode >= OpcodeRangeDefine.InnerMinOpcode;
    }

    public static LogMsg(zone: number, message: Object): void {
        let opcode = NetServices.Instance.GetOpcode(GetTypeOf(message));
        if (!this.IsNeedLogMessage(opcode)) {
            return;
        }
        Logger.Instance.Debug(`zone: ${zone} ${message}`);
    }

}